<?php
defined('SYSPATH') or die('No direct script access.');

class Model_DishItem extends Model_Base{
	
	protected $_table_name  = 'dish_item';
	protected $_table_names_plural = false;
	public $dic = array("C"=>"冷","H"=>"热","S"=>"小","M"=>"中","L"=>"大");
	
	protected function modelWithCondition($filters){
		$model = $this->where("status","<>","I");
		return $model;
	}
	
	public function insert($dataArray){
		if($this->values($dataArray)->check()){
			return $this->save();
		}
		return false;
	}
	
	public function update($dataArray){
		$dataArray = array_slice($dataArray, 1, sizeof($dataArray));//remove id
		if($this->values($dataArray)){
			return $this->save();
		}
		return false;
	}
	
	public function displayWithPrice(){
		$msg = "";
		if (!empty($this->size)&&empty($this->temp)){
			$msg = $this->dic[$this->size];
		}elseif (empty($this->size)&&!empty($this->temp)){
			$msg = $this->dic[$this->temp];
		}elseif (!empty($this->size)&&!empty($this->temp)){
			$msg = $this->dic[$this->size].'&'.$this->dic[$this->temp];
		}
		return $msg.'------>'.$this->dislayPrice($this->price).'(元)';
	}
	
	public function displaySize(){
		if (!empty($this->size)){
			return $this->dic[$this->size];
		}
		return "";
	}
	
	public function displayTemp(){
		if (!empty($this->temp)){
			return $this->dic[$this->temp];
		}
		return "";
	}
	
	public function dislayPrice($price){
		if($price == 9999){
			return '时价';
		}elseif($price == 0){
			return '暂无';
		}else{
			return $price;
		}
	}
}